package com.neusoft.di.dibuy.controller;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.reactive.DispatcherHandler;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.time.Duration;

@RestController
@RequestMapping("t")
public class TestController {



    @RequestMapping( value =  "/t4" , produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> t4(){
        return  Flux.range(1,100)
                .map(  i ->  ("Index :  --- >" +  i )   )
                .delayElements(Duration.ofSeconds(1))
                ;

    }




    @RequestMapping("/t3")
    public Flux<Dog> t3(){
        DispatcherHandler dispatcherHandler =null;
        return  Flux.just( new Dog("dog1",1),new Dog("dog2",2) );




    }





    @RequestMapping("/t2")
    public Mono<String> t1(){
        return Mono.just("t1");
    }



    @RequestMapping("/t1")
    public String test(){
        return "test";
    }


    public  static   class  Dog{
        private  String  name ="dog";
        private  int  age = 12;

        public Dog(String name, int age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }
    }

}
